<?php
/**
 * Created by PhpStorm.
 * User: huqb
 * Date: 15/5/13
 * Time: 下午4:32
 */
    class Validate {
        private $token;

        public function __construct() {
//            parent::__construct();
            $this->CI =& get_instance();
            $this->CI->load->config('token');
            $this->token = $this->CI->config->item('token');
        }
        //验证签名
        public function valid()
        {
            $echoStr = $_GET["echostr"];
            $signature = $_GET["signature"];
            $timestamp = $_GET["timestamp"];
            $nonce = $_GET["nonce"];
            $token = $this->token;
            $tmpArr = array($token, $timestamp, $nonce);
            sort($tmpArr);
            $tmpStr = implode($tmpArr);
            $tmpStr = sha1($tmpStr);
            if($tmpStr == $signature){
                echo $echoStr;
                exit;
            }else{
                echo 'valid false';
            }
        }
    }